<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-search"
          size="mini"
          @click="handleSearch"
          >搜索</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['purchase:lqmMstr:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['purchase:lqmMstr:edit']"
        >
          修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="single"
          @click="handleDelete"
          v-hasPermi="['purchase:lqmMstr:remove']"
        >
          删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="single1"
          @click="check_invalid = true"
          v-hasPermi="['purchase:lqmMstr:invalid']"
        >
          作废
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['purchase:lqmMstr:export']"
        >
          导出
        </el-button>
      </el-col>
      <el-col :span="2.2" style="position: absolute; right: 0px; top: 0">
        <Page
          style="margin-right: 0px"
          :current="queryParams.pageNum"
          :page-size="queryParams.pageSize"
          :total="total"
          @on-change="pageChange"
          simple
        ></Page>
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      highlight-current-row
      border
      stripe
      v-loading="loading"
      :data="lqmMstrList"
      :height="tableH"
      @row-click="clickRow"
      :header-cell-style="{ 'text-align': 'center' }"
      :cell-style="iCellStyle"
    >
      <el-table-column label="#" width="40" type="index" align="center" />
      <el-table-column
        label="请购单号"
        :show-overflow-tooltip="true"
        width="135"
        align="center"
        prop="lqmDjbh"
      />
      <el-table-column
        label="请购部门"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="lqmBmdm"
      >
        <template v-slot="scope">
          <dict-tag :options="deptList" :value="scope.row.lqmBmdm" />
        </template>
      </el-table-column>
      <el-table-column
        label="需求日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="lqmXqrq"
        width="150"
      >
        <template #default="scope">
          <span>{{
            parseTime(scope.row.lqmXqrq, "{y}-{m}-{d} {h}:{i}:{s}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="品名规格"
        :show-overflow-tooltip="true"
        width="300"
        prop="lqmPmgg"
      />
      <el-table-column
        label="请购数量"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="lqmQgsl"
      />
      <el-table-column
        label="单位"
        :show-overflow-tooltip="true"
        width="80"
        align="center"
        prop="lqmDw"
      >
        <template v-slot="scope">
          <dict-tag :options="unitOptions" :value="scope.row.lqmDw" />
        </template>
      </el-table-column>
      <el-table-column
        label="参考单价"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="lqmCkdj"
      />
      <el-table-column
        label="备注"
        :show-overflow-tooltip="true"
        width="200"
        prop="lqmDesc"
      />
      <el-table-column
        label="订单状态"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="lqmZtbzmc"
      />
      <el-table-column
        label="撤回原因"
        :show-overflow-tooltip="true"
        width="100"
        prop="lqmNgdesc"
      />
      <el-table-column
        label="建立人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="lqmJlry"
      />
      <el-table-column
        label="建立日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="lqmJlrq"
        width="150"
      >
        <template #default="scope">
          <span>{{
            parseTime(scope.row.lqmJlrq, "{y}-{m}-{d} {h}:{i}:{s}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="审核人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="lqmShry"
      />
      <el-table-column
        label="审核日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="lqmShrq"
        width="150"
      >
        <template #default="scope">
          <span>{{
            parseTime(scope.row.lqmShrq, "{y}-{m}-{d} {h}:{i}:{s}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="批准人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="lqmPzry"
      />
      <el-table-column
        label="批准日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="lqmPzrq"
        width="150"
      >
        <template #default="scope">
          <span>{{
            parseTime(scope.row.lqmPzrq, "{y}-{m}-{d} {h}:{i}:{s}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="物料代码"
        :show-overflow-tooltip="true"
        width="135"
        align="center"
        prop="lqmWldm"
      />
    </el-table>
    <div>
      <span>
        <img style="width: auto; height: 200px" :src="srcLqm" alt="" />
      </span>
    </div>

    <!-- 查询对话框   -->
    <el-dialog
      :title="title"
      v-model="openSearch"
      :close-on-click-modal="false"
      draggable
      width="600px"
      append-to-body
    >
      <el-form
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        v-show="showSearch"
        label-width="68px"
      >
        <el-col :span="24">
          <el-form-item label="建立日期">
            <el-date-picker
              v-model="dateRange"
              size="small"
              style="width: 480px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :default-time="['00:00:00', '23:59:59']"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="请购单号">
            <el-input
              v-model="queryParams.lqmDjbh"
              style="width: 480px"
              placeholder="请输入请购单号"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="请购部门">
            <el-select
              placeholder="请选择请购部门"
              size="small"
              v-model="queryParams.lqmBmdm"
              style="width: 480px"
              clearable
            >
              <el-option
                v-for="item in deptList"
                :key="item.dictValue"
                :label="item.dictLabel"
                :value="item.dictValue"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="品名规格">
            <el-input
              v-model="queryParams.lqmPmgg"
              placeholder="请输入品名规格"
              style="width: 480px"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item>
            <el-radio-group v-model="queryParams.lqmZtbz">
              <el-radio label="1" style="margin-left: 20px">未审核</el-radio>
              <el-radio label="2">已审核未批准</el-radio>
              <el-radio label="3">已审核已批准</el-radio>
              <el-radio label="4">采购中</el-radio>
              <el-radio label="5">已入库</el-radio>
              <el-radio label="-1">全部</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item
            style="margin-top: 5px; display: flex; justify-content: flex-end"
          >
            <el-button @click="cancel">取消</el-button>
            <el-button type="primary" @click="handleQuery">确认</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-dialog>

    <!-- 添加零星请购单对话框 -->
    <el-dialog
      :title="title"
      v-model="openAdd"
      :close-on-click-modal="false"
      width="1000px"
      :destroy-on-close="true"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <div style="display: flex">
          <div style="width: 660px; display: flex; flex-wrap: wrap">
            <el-form-item label="需求日期" prop="lqmXqrq">
              <el-date-picker
                clearable
                size="mini"
                v-model="form.lqmXqrq"
                type="datetime"
                style="width: 240px"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择需求日期"
              ></el-date-picker>
            </el-form-item>
            <el-form-item label="物料代码" prop="lqmWldm">
              <el-input
                v-model="form.lqmWldm"
                style="width: 240px"
                size="mini"
                readonly
                placeholder="筛选后,点击应用生成"
              />
            </el-form-item>
            <el-form-item label="产品名称" prop="lqmwlpm">
              <el-input
                v-model="form.lqmwlpm"
                style="width: 240px"
                size="mini"
                readonly
                placeholder="筛选后,点击应用生成"
              />
            </el-form-item>
            <el-form-item label="产品规格" prop="lqmwlgg">
              <el-input
                v-model="form.lqmwlgg"
                style="width: 240px"
                size="mini"
                readonly
                placeholder="筛选后,点击应用生成"
              />
            </el-form-item>
            <el-form-item label="品名规格" prop="lqmPmgg">
              <el-input
                v-model="form.lqmPmgg"
                style="width: 240px"
                size="mini"
                readonly
                placeholder="筛选后,点击应用生成"
              />
            </el-form-item>
            <el-form-item label="单位" prop="lqmDw">
              <el-select
                v-model="form.lqmDw"
                style="width: 240px"
                size="mini"
                placeholder="筛选后,点击应用生成"
                disabled
              >
                <el-option
                  v-for="dict in unitOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="产品筛选" prop="filterPmgg">
              <el-input
                @input="handleSearchQF()"
                style="width: 240px"
                size="mini"
                v-model="filterPmgg"
                placeholder="输入名称来筛选"
              />
            </el-form-item>
            <el-form-item label="请购数量" prop="lqmQgsl">
              <el-input
                v-model="form.lqmQgsl"
                style="width: 240px"
                size="mini"
                placeholder="请输入请购数量"
              />
            </el-form-item>
            <el-form-item label="用途" prop="lqmDesc">
              <el-input
                v-model="form.lqmDesc"
                style="width: 240px"
                size="mini"
                placeholder="请输入用途"
              />
            </el-form-item>
            <el-form-item label="参考单价" prop="lqmCkdj">
              <el-input
                v-model="form.lqmCkdj"
                style="width: 240px"
                size="mini"
                placeholder="请输入参考单价"
              />
            </el-form-item>
          </div>
          <div style="height: 200px; width: 300px">
            <img :src="srcUrl" style="width: 200px; height: auto" alt="" />
          </div>
        </div>
      </el-form>
      <el-table
        v-if="openAdd"
        highlight-current-row
        border
        stripe
        @scrollBottom="load1"
        v-loading="loading"
        height="200px"
        :data="selectedItmMstr"
        :header-cell-style="{ 'text-align': 'center' }"
        empty-text="申请物料物料编码必须已建立,才能申请"
      >
        <el-table-column label="#" width="40" type="index" align="center" />
        <el-table-column
          label="物料代码"
          :show-overflow-tooltip="true"
          align="center"
          prop="lqmWldm"
        />
        <el-table-column
          label="名称"
          :show-overflow-tooltip="true"
          align="center"
          prop="lqmwlpm"
        />
        <el-table-column
          label="规格"
          :show-overflow-tooltip="true"
          align="center"
          prop="lqmwlgg"
        />
        <el-table-column
          label="单位"
          :show-overflow-tooltip="true"
          align="center"
          prop="lqmDw"
        >
          <template #default="scope">
            <dict-tag :options="unitOptions" :value="scope.row.lqmDw" />
          </template>
        </el-table-column>
        <el-table-column
          label="参考单价"
          :show-overflow-tooltip="true"
          align="center"
          prop="lqmCkdj"
        />
        <el-table-column
          label="库存"
          :show-overflow-tooltip="true"
          align="center"
          prop="lqmKcsl"
        />
        <el-table-column
          label="操作"
          align="center"
          fixed="right"
          :show-overflow-tooltip="true"
          width="100"
          class-name="small-padding fixed-width"
        >
          <template #default="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleApply(scope.row)"
              >应用</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>

    <!-- 修改零星请购单对话框 -->
    <el-dialog
      :title="title"
      v-model="openEdit"
      :close-on-click-modal="false"
      draggable
      width="780px"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="请购单号" prop="lqmDjbh">
              <el-input v-model="form.lqmDjbh" disabled />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="需求日期" prop="lqmXqrq">
              <el-date-picker
                clearable
                size="small"
                v-model="form.lqmXqrq"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择需求日期"
              ></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="品名规格" prop="lqmPmgg">
              <el-input
                v-model="form.lqmPmgg"
                readonly
                placeholder="筛选后,点击应用生成"
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="请购数量" prop="lqmQgsl">
              <el-input v-model="form.lqmQgsl" placeholder="请输入请购数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单位" prop="lqmDw">
              <el-select
                v-model="form.lqmDw"
                placeholder="筛选后,点击应用生成"
                disabled
              >
                <el-option
                  v-for="dict in unitOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="用途" prop="lqmDesc">
              <el-input v-model="form.lqmDesc" placeholder="请输入用途" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>

    <Modal v-model="check_invalid" width="360" draggable scrollable>
      <p slot="header" style="color: #f60; text-align: center">
        <Icon type="ios-information-circle"></Icon>
        <span>确认作废？</span>
      </p>
      <div style="text-align: center">
        <p>确认要将此物料作废？一旦作废，该单据将永久失效，请谨慎操作！</p>
        <Input
          style="width: 80%"
          placeholder="作废理由"
          v-model="invalidReason"
        />
      </div>
      <div slot="footer">
        <Button type="error" size="large" long @click="handleInvalid"
          >作废</Button
        >
      </div>
    </Modal>
  </div>
</template>

<script>
import {
  listLqmMstr,
  getLqmMstr,
  delLqmMstr,
  addLqmMstr,
  updateLqmMstr,
  searchQF,
  getImg,
  invalidLqm,
  exportLqm,
} from "@/api/purchase/lqmMstr";
import { listDept } from "@/api/system/dept";
import { getImageByWldm } from "@/api/project/materiel";
import { exportModelRepair } from "@/api/device/modelRepair";

export default {
  name: "LqmMstr",
  data() {
    return {
      // 遮罩层
      loading: true,
      srcUrl: null,
      // 导出遮罩层
      exportLoading: false,
      // 选中数据
      rowData: {},
      srcLqm: null,
      tableH: document.body.clientHeight > 700 ? 550 : 300,
      check_invalid: false,
      invalidReason: "",
      // 非单个禁用
      single: true,
      single1: true,
      // 显示搜索条件
      showSearch: true,
      openSearch: false,
      // 总条数
      total: 0,
      total1: 0,
      // 零星请购单表格数据
      lqmMstrList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      openAdd: false,
      openEdit: false,
      // 建立日期时间范围
      dateRange: [
        new Date(new Date().getTime() - 1000 * 60 * 60 * 24 * 60),
        new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * 60),
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 25,
        lqmDjbh: null,
        lqmZtbz: "-1",
        lqmPmgg: null,
        lqmJlrq: null,
      },
      queryParamsChild: {
        pageNum: 1,
        pageSize: 25,
        lqmPmgg: null,
      },
      // 表单参数
      form: {},
      // 产品筛选
      filterPmgg: null,
      // 筛选后的物料List
      selectedItmMstr: [],
      // 表单校验
      rules: {
        lqmDesc: [{ required: true, message: "用途不能为空", trigger: "blur" }],
        lqmWldm: [
          { required: true, message: "物料代码不能为空", trigger: "blur" },
        ],
        lqmQgsl: [
          { required: true, message: "请购数量不能为空", trigger: "blur" },
        ],
      },
      //单位字典
      unitOptions: [],
      //部门字典
      deptList: [],
    };
  },
  created() {
    //获取全部单位
    this.getAllDicts("sys_unit").then((response) => {
      this.unitOptions = response.data;
    });
    // 获取全部部门
    listDept({ parentId: 100 }).then((res) => {
      this.deptList = res.data;
      for (let item of this.deptList) {
        if (item.deptId !== 116) {
          item.dictLabel = item.deptName;
          item.listClass = "default";
          item.dictValue = item.deptId + "";
        } else {
          this.deptList.splice(this.deptList.indexOf(item), 1);
        }
      }
    });
    this.getList();
  },
  methods: {
    iCellStyle({ row, column, rowIndex, columnIndex }) {
      //审核状态
      if (row.lqmZtbz == "2") {
        return "color:#3399ff";
      }
      //批准状态
      else if (row.lqmZtbz == "4") {
        return "color:#bb0331";
      }
    },
    pageChange(page) {
      this.queryParams.pageNum = page;
      this.getList();
    },
    /** 查询零星请购单列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.dateRange && "" != this.dateRange) {
        this.queryParams.params["beginLqmJlrq"] = this.moment(
          this.dateRange[0]
        ).format("YYYY-MM-DD 00:00:00");
        this.queryParams.params["endLqmJlrq"] = this.moment(
          this.dateRange[1]
        ).format("YYYY-MM-DD 23:59:59");
      }
      listLqmMstr(this.queryParams).then((response) => {
        this.lqmMstrList = [];
        this.lqmMstrList = this.lqmMstrList.concat(response.rows);
        this.total = response.total;
        this.loading = false;
      });
    },

    load1() {
      if (
        this.queryParamsChild.pageNum <
        Math.ceil(this.total1 / this.queryParamsChild.pageSize)
      ) {
        this.queryParamsChild.pageNum++;
        searchQF(this.queryParamsChild).then((response) => {
          this.selectedItmMstr = this.selectedItmMstr.concat(response.rows);
          this.total1 = response.total;
          this.loading = false;
        });
      }
      return 0;
    },
    // 取消按钮
    cancel() {
      this.openAdd = false;
      this.openEdit = false;
      this.openSearch = false;
      this.srcUrl = null;
      this.reset();
    },
    // 表单重置
    reset() {
      this.filterPmgg = null;
      this.form = {
        lqmId: null,
        lqmDjbh: null,
        lqmBmdm: null,
        lqmXqrq: new Date(),
        lqmWldm: null,
        lqmDw: null,
        lqmwlpm: null,
        lqmwlgg: null,
        lqmPmgg: null,
        lqmQgsl: null,
        lqmCkdj: null,
        lqmKcsl: null,
        lqmZtbz: null,
        lqmFlag: null,
        lqmDesc: null,
        lqmNgdesc: null,
        lqmJlry: null,
        lqmJlrq: null,
        lqmShry: null,
        lqmShrq: null,
        lqmPzry: null,
        lqmPzrq: null,
        lqmQrry: null,
        lqmQrrq: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.lqmMstrList = [];
      this.getList();
      this.openSearch = false;
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 选中数据
    clickRow(row) {
      this.rowData = row;
      this.single = row == null || row.lqmZtbz != 1 || row.lqmFlag != 0;
      this.single1 = row == null || row.lqmZtbz == 4 || row.lqmZtbz == 3;
      if (row != null) {
        getImageByWldm(row.lqmWldm)
          .then((res) => {
            this.srcLqm = process.env.VUE_APP_BASE_API + res.msg;
          })
          .catch(() => {
            this.msgError("获取失败");
          });
      }
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.openAdd = true;
      this.title = "添加零星请购单";
    },
    /** 搜索物料 */
    handleSearchQF() {
      if (this.filterPmgg != null && this.filterPmgg != "") {
        this.queryParamsChild.pageNum = 1;
        this.queryParamsChild.lqmPmgg = this.filterPmgg;
        searchQF(this.queryParamsChild)
          .then((res) => {
            this.selectedItmMstr = res.rows;
            this.total1 = res.total;
          })
          .catch(() => {
            this.msgError("查询失败");
          });
      } else {
        setTimeout(() => {
          this.selectedItmMstr = [];
        }, 400);
      }
    },
    /** 应用 */
    handleApply(row) {
      this.form.lqmWldm = row.lqmWldm;
      this.form.lqmwlpm = row.lqmwlpm;
      this.form.lqmwlgg = row.lqmwlgg;
      this.form.lqmPmgg = row.lqmPmgg;
      this.form.lqmDw = row.lqmDw;
      this.form.lqmCkdj = row.lqmCkdj;
      this.msgSuccess("成功");
      getImg(row.lqmWldm).then((response) => {
        console.log(response);
        this.srcUrl = process.env.VUE_APP_BASE_API + response.msg;
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const lqmId = this.rowData.lqmId;
      getLqmMstr(lqmId).then((response) => {
        this.form = response.data;
        this.openEdit = true;
        this.title = "修改零星请购单";
      });
    },
    handleSearch() {
      this.reset();
      this.title = "查询零星请购单";
      this.openSearch = true;
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.lqmXqrq != null) {
            this.form.lqmXqrq = this.moment(this.form.lqmXqrq).format(
              "YYYY-MM-DD HH:mm:ss"
            );
          }
          if (this.form.lqmId != null) {
            updateLqmMstr(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.openEdit = false;
              this.getList();
            });
          } else {
            addLqmMstr(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.openAdd = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const lqmId = this.rowData.lqmId;
      this.$confirm(
        '是否确认删除零星请购单编号【"' + this.rowData.lqmDjbh + '"】的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delLqmMstr(lqmId);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 作废按钮操作 */
    handleInvalid() {
      invalidLqm(this.rowData.lqmId, this.invalidReason)
        .then((res) => {
          this.getList();
          this.check_invalid = false;
          this.invalidReason = null;
          this.msgSuccess("作废成功");
        })
        .catch(() => {
          this.msgError("作废失败");
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.exportLoading = true;
          return exportLqm(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
  },
};
</script>

<style lang="scss" scoped>
.lqmmstr {
  ::v-deep .inputWidth {
    width: 240px;
  }

  ::v-deep .el-form-item {
    margin-bottom: 5px;
  }

  ::v-deep .el-dialog__body {
    padding: 0 20px;
  }

  ::v-deep .el-form-item__error {
    top: 10px;
    left: 140px;
  }

  ::v-deep .el-radio {
    margin-right: 10px;
  }
}
</style>
